{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Count the Digits That Divide a Number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: countDigits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #统计能整除数字的位数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数 <code>num</code> ，返回 <code>num</code> 中能整除 <code>num</code> 的数位的数目。</p>\n",
    "\n",
    "<p>如果满足&nbsp;<code>nums % val == 0</code> ，则认为整数 <code>val</code> 可以整除 <code>nums</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>num = 7\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>7 被自己整除，因此答案是 1 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>num = 121\n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：</strong>121 可以被 1 整除，但无法被 2 整除。由于 1 出现两次，所以返回 2 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>num = 1248\n",
    "<strong>输出：</strong>4\n",
    "<strong>解释：</strong>1248 可以被它每一位上的数字整除，因此答案是 4 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= num &lt;= 10<sup>9</sup></code></li>\n",
    "\t<li><code>num</code> 的数位中不含 <code>0</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [count-the-digits-that-divide-a-number](https://leetcode.cn/problems/count-the-digits-that-divide-a-number/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [count-the-digits-that-divide-a-number](https://leetcode.cn/problems/count-the-digits-that-divide-a-number/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['7', '121', '1248']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDigits(self, num: int) -> int:\n",
    "        return sum(\n",
    "            1 if num % int(d) == 0 else 0 \n",
    "            for d in str(num)\n",
    "        )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDigits(self, num: int) -> int:\n",
    "        tmp, res = num, 0\n",
    "        while num:\n",
    "            num, d = divmod(num, 10)\n",
    "            if tmp % d == 0:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDigits(self, num: int) -> int:\n",
    "\n",
    "        test = [int(n) for n in str(num)]\n",
    "\n",
    "        count = 0\n",
    "\n",
    "        for val in test:\n",
    "            if num % val == 0:\n",
    "                count += 1\n",
    "        \n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDigits(self, num: int) -> int:\n",
    "        ans = 0\n",
    "        for c in str(num):\n",
    "            if num % int(c) == 0: ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def countDigits(self, num: int) -> int:\r\n",
    "        count = 0\r\n",
    "        convert = str(num)\r\n",
    "        for char in convert:\r\n",
    "            if num % int(char) == 0:\r\n",
    "                count += 1\r\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MOD = int(1e9 + 7)\n",
    "INF = int(1e20)\n",
    "\n",
    "import sortedcontainers\n",
    "import bisect\n",
    "class Solution:\n",
    "    def countDigits(self, num: int) -> int:\n",
    "        s = str(num)\n",
    "        ans = 0\n",
    "        for c in s:\n",
    "            t = int(c)\n",
    "            if num % t == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDigits(self, num: int) -> int:\n",
    "        nums = [int(i) for i in str(num)]\n",
    "        ans = 0\n",
    "        for i in nums:\n",
    "            if num%i == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDigits(self, num: int) -> int:\n",
    "        ans = 0\n",
    "        x = num\n",
    "        while x:\n",
    "            ans += num % (x % 10) == 0\n",
    "            x //= 10\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDigits(self, num: int) -> int:\n",
    "        n=0\n",
    "        a=[]\n",
    "        for i in str(num):\n",
    "            a.append(i)\n",
    "        print(a)\n",
    "        for i in range(len(a)):\n",
    "            if num%int(a[i])==0:\n",
    "                n=n+1\n",
    "        return n\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
